package com.chookss.home.publish.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.chookss.R;
import com.chookss.base.BaseViewHolderEx;
import com.chookss.home.entity.LogEntity;
import com.chookss.tools.MyEvent;
import com.chookss.tools.filePicker.util.FileUtils;

import org.greenrobot.eventbus.EventBus;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DocunmentListAdapter extends BaseQuickAdapter<LogEntity.DocunmentBean, BaseViewHolderEx> {
    private Context context;
    public DocunmentListAdapter(int layoutResId,  Context context,@io.reactivex.annotations.Nullable List<LogEntity.DocunmentBean> data) {
        super(layoutResId, data);
        this.context=context;
    }
    @Override
    protected void convert(BaseViewHolderEx helper, LogEntity.DocunmentBean entity) {
        ImageView ivIconType = helper.getView(R.id.iv_item_file_select_left);
        TextView tvItemTitle = helper.getView(R.id.tv_item_file_list);
        TextView tvItemDate = helper.getView(R.id.tv_item_file_list_desc);
        RelativeLayout rlStatus = helper.getView(R.id.rlStatus);
//            String fileType = entity.getFileType();//文件类型1--word 2 --excel 3--PPT  4pdf.
        tvItemTitle.setText(entity.getDataTitle());
        tvItemDate.setText(String.format(context.getString(R.string.file_desc),entity.getDataTime(), entity.getDataSize()));
        rlStatus.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Map<String, String> map = new HashMap<>();
                map.put("position", helper.getItemPosition() + "");
                map.put("deleteDocunment", "deleteDocunment");
                EventBus.getDefault().post(new MyEvent(map));
            }
        });
        String fileNameExtension = FileUtils.getExtension(entity.getDataTitle()).toLowerCase();
        switch (fileNameExtension) {
            case "doc":
            case "docx":
                ivIconType.setImageResource(R.drawable.icon_w_80);
                break;
            case "pdf":
                ivIconType.setImageResource(R.drawable.icon_pdf_80);
                break;
            case "ppt":
            case "pptx":
                ivIconType.setImageResource(R.drawable.icon_p_80);
                break;
            case "xls":
            case "xlsx":
                ivIconType.setImageResource(R.drawable.icon_x_80);
                break;
            case "ext":
            default:
                ivIconType.setImageResource(R.drawable.icon_mr_80);
                break;
        }
    }

}
